<template>
  <div>
    <el-row>
      <el-col :span="4"><div class="grid-content bg-purple"></div></el-col>
      <el-col :span="4">
        <div class="grid-content bg-purple-light">
          <el-button type="primary" @click="recruitAdd">发布招聘</el-button>
        </div>
      </el-col>
      <el-col :span="4"><div class="grid-content bg-purple"></div></el-col>
      <el-col :span="4">
        <div class="grid-content bg-purple-light"></div>
      </el-col>
      <el-col :span="4"><div class="grid-content bg-purple"></div></el-col>
      <el-col :span="4">
        <div class="grid-content bg-purple-light"></div>
      </el-col>
    </el-row>

    <el-table :data="recruits" style="width: 100%">
      <el-table-column type="index" width="50"></el-table-column>
      <!-- <el-table-column label="comID" prop="comId"></el-table-column> -->
      <el-table-column label="招聘岗位" prop="post"></el-table-column>
      <el-table-column label="招聘人数" prop="number"></el-table-column>
      <el-table-column label="工资(单位:K)" prop="salary"></el-table-column>
      <el-table-column label="专业要求" empty-text prop="major">
      </el-table-column>
      <el-table-column label="工作内容" prop="content"></el-table-column>
      <el-table-column label="发布时间" prop="reTime"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="recruitEdit(scope.row)">
            编辑
          </el-button>
          <el-button
            size="mini"
            type="danger"
            @click="recruitDelete(scope.row)"
          >
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      background
      layout="prev, pager, next"
      :current-page="currentPage"
      :page-size="pageSize"
      :total="total"
      @current-change="page"
    >
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: "RInformation",
  data() {
    return {
      id: 1,
      recruits: [], // 数据
      currentPage: 1, // 当前页
      total: 0, // 总页数
      pageSize: 5, // 一页有多少内容
    };
  },
  created() {
    this.page(1);
  },
  methods: {
    page(currentPage) {
      const _this = this;
      const id = _this.$store.getters.getCompany.id;

      _this.$axios
        .get("/rec/" + id + "?currentPage=" + currentPage)
        .then((res) => {
          // console.log(res);
          _this.recruits = res.data.data.records;
          _this.currentPage = res.data.data.current;
          _this.total = res.data.data.total;
          _this.pageSize = res.data.data.size;
        });
    },

    recruitAdd() {
      this.$router.push("/company/rEdit");
    },

    recruitEdit(e) {
      this.$router.push({
        path: "/company/rEdit",
        query: {
          id: e.id,
        },
      });
    },

    recruitDelete(e) {
      this.$confirm("是否删除该招聘信息?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          const _this = this;
          _this.$axios.get("/delRecruit/" + e.id).then((res) => {
            console.log(res);
            window.location.reload();
            this.$message({
              type: "success",
              message: "删除成功!",
            });
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
};
</script>

<style scoped>
</style>
